package com.xcm.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.xcm.constant.PageConstant;
import com.xcm.model.dto.ProgramJsonListDTO;
import com.xcm.model.vo.ProgramJsonStatVO;
import com.xcm.service.ProgramJsonService;

@Controller	
@RequestMapping(value = "/programJson")	
public class ProgramJsonController {
	@Autowired
	private ProgramJsonService programJsonService;
	
	/**
	 * 发布列表
	 */
	@RequestMapping(value = "/listPage")
	public String getProgramJsons( Model model) {
		ProgramJsonStatVO stat =  programJsonService.getProgramJsonStat();
		model.addAttribute("count_total",stat.getTotalCount());
		model.addAttribute("count_success",stat.getSuccessCount());
		model.addAttribute("count_failed",stat.getFailedCount());
		model.addAttribute("count_downloading",stat.getDownloadingCount());
		return "program_list";
	}
	
	/**
	 * 发布列表 ajax get Json Data
	 */
	@RequestMapping(value = "/getProgramJsons")
	@ResponseBody
	public Object listData(String timeType,String startTime,String endTime,String deviceDownState,String checkType,Long publishId, Integer pageNum, Integer pageSize) {
		pageNum = ( pageNum == null ? PageConstant.DEFAULT_PAGE_NUM : pageNum ) ;
		pageSize = ( pageSize == null ? PageConstant.DEFAULT_PAGE_SIZE : pageSize );
		Page<ProgramJsonListDTO> page = programJsonService.listProgramJsonByPage(timeType, startTime, endTime, deviceDownState, checkType, publishId, pageNum, pageSize);
		Map<String,Object> map = new HashMap<>();
		map.put("record", page.getResult());
		map.put("pageNum", page.getPageNum());
		map.put("pageSize", page.getPageSize());
		map.put("total", page.getTotal());

		ProgramJsonStatVO stat =  programJsonService.getProgramJsonStat();
		map.put("count_total",stat.getTotalCount());
		map.put("count_success",stat.getSuccessCount());
		map.put("count_failed",stat.getFailedCount());
		map.put("count_downloading",stat.getDownloadingCount());
		return map;
	}
}
